package com.topnav.mc.admin.controller.Fence;

import com.js.lib.annotation.ApiLogger;
import com.js.lib.result.Result;
import com.topnav.mc.admin.bean.OrgDeviceBean;
import com.topnav.mc.admin.service.IFenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: kenny
 * @Date: 2023/11/14 16:51
 */
@Api(value = "admin/fence/tree", tags = "围栏查询")
@RestController
@CrossOrigin
@RequestMapping("admin/fence/tree")
public class FenceTreeController {

    @Autowired
    private IFenceService fenceService;

    /**
     * 带单位树型结构的围栏列表
     * 给前端 Tree组件使用
     * 没有输入id参数时，查询第一层（有权限控制）
     * 有id时则查询些id的下一级
     * */
    @ApiLogger(apiName="/find/for/org")
    @ApiOperation(value = "带单位树型结构的设备列表")
    @ApiImplicitParams(
            {@ApiImplicitParam(name="id", value = "单位id", required=false,dataTypeClass = String.class)})
    @GetMapping("/find/for/org")
    @ResponseBody
    public Result findFenceForOrgTrue(String id) {
        return fenceService.findFenceTree(id);
    }


    /**
     * 按输入值查询的围栏列表
     * @param keyword
     * @return
     */
    @ApiLogger(apiName="/find/by/keyword")
    @ApiOperation(value = "输入值查询列表")
    @ApiImplicitParams(
            {@ApiImplicitParam(name="keyword", value = "关键字", required=false,dataTypeClass = String.class)
                    ,@ApiImplicitParam(name="state", value = "状态(1在线,-1离线,0全部)", required=false,dataTypeClass = Integer.class)})
    @GetMapping("/find/by/keyword")
    @ResponseBody
    public Result findFenceByKeyword(String keyword) {

        Result result = fenceService.searchBykeyword(keyword);
 /*       if (null != result.getData() && result.getData() instanceof List){
            this.setPosition((List<OrgDeviceBean>)result.getData());
        }*/
        return result;
    }


}
